{
  LX ImageMon module

  Based on modo's SDK lximagemon.h which is:

  Copyright (c) 2008-2012 Luxology LLC

  Permission is hereby granted, free of charge, to any person obtaining a
  copy of this software and associated documentation files (the "Software"),
  to deal in the Software without restriction, including without limitation
  the rights to use, copy, modify, merge, publish, distribute, sublicense,
  and/or sell copies of the Software, and to permit persons to whom the
  Software is furnished to do so, subject to the following conditions:

  The above copyright notice and this permission notice shall be included in
  all copies or substantial portions of the Software.   Except as contained
  in this notice, the name(s) of the above copyright holders shall not be
  used in advertising or otherwise to promote the sale, use or other dealings
  in this Software without prior written authorization.

  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
  FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
  DEALINGS IN THE SOFTWARE.
}

{
  Copyright (c) 2012 David Ballesteros and Jameel Halabi

  This unit is part of the BLAISEmodo wrapper,
  which is licensed under the BSD 2-Clause license (see licenses/license.txt).
}


unit Lx_ImageMon;

{$mode objfpc}{$H+}

interface

uses
  Lx_Result, Lx_Value, Lx_RndJob, Lx_Command, Lx_Image;

const
  LXa_IMAGEMONITOR                = 'imagemonitor'       ;
  LXa_IMAGEMONITORSERVICE         = 'imagemonitorservice';

  // Mask off the event
  LXfIPEVENT_EVENT                =  $FFFFFFF0;
  // Mask off the invalidation flags
  LXfIPEVENT_FLAGS                =  $0000000F;

  LXsIMAGEMONITOR_SOURCE_NOTIFIER = 'notifier.imagemonitor.source';
  LXsIMAGEPROC_NOTIFIER           = 'notifier.imageproc'          ;

  LXu_IMAGEMONITOR                = '{5ef021ed-a2e3-48d3-aba1-7cbb815f15b7}';
  LXu_IMAGEMONITORSERVICE         = '{f59258f8-3e86-408f-9e92-f81a21d01bde}';

type
  PPLXtImageMonitorPacket = ^PLXtImageMonitorPacket;
  PLXtImageMonitorPacket  = ^LXtImageMonitorPacket;
  LXtImageMonitorPacket   = record
    Image              : ILxImage              ;

    FrameBuffer        : ILxFrameBuffer        ;
    BufferIndex        : Integer               ;

    X1, Y1, X2, Y2     : Double                ;

    ImageProc          : ILxImageProcessing    ;

    ProcessedThumbnail : ILxImage              ;

    ImageSource        : array [0..255] of Char;
  end;

  ILxImageMonitor = interface
  [LXu_IMAGEMONITOR]
    function Image
             (      ImageToAnalyze,
                    FrameBufferToAnalyze : IUnknown;
                    BufferIndex          : Integer ;
		    X1, Y1,
                    X2, Y2               : Double  ;
		    ImageProcessingRead  ,
                    ProcessedThumbnail   : IUnknown) : LxResult;

    function ImageProcChanged                        : LxResult;

    function AspectRange
             (      MinAspect, MaxAspect ,
                    IdealAspect          : PDouble ) : LxResult;

    function Draw
             (      ImageForDrawing      : IUnknown) : LxResult;

    function ImageSource
             (const Source               : PChar   ) : LxResult;

    function MouseDown
             (      StartX, StartY,
                    W, H                 : Integer ) : LxResult;

    function MouseMove
             (      StartX, StartY,
                    CX, CY,
                    W, H                 : Integer ) : LxResult;

    function MouseUp
             (      StartX, StartY,
                    CX, CY,
                    W, H                 : Integer ) : LxResult;

    function MouseTrackEnter                         : LxResult;

    function MouseTrack
             (      CX, CY,
                    W, H                 : Integer ) : LxResult;

    function MouseTrackExit                          : LxResult;

    function ToolTip
             (      CX, CY,
                    W, H                 : Integer ;
                    Buffer               : PChar   ;
		    Len                  : UInt32  ) : LxResult;
  end;

  ILxImageMonitorService = interface
  [LXu_IMAGEMONITORSERVICE]
    function ScriptQuery
             (  out VObj                                             )
                                                                     : LxResult;

    function ServerCount
             (      Count                   : PInteger               )
                                                                     : LxResult;

    function ServerByIndex
             (      Index                   : Integer                ;
                out VObj                                             )
                                                                     : LxResult;

    function ServerLookup
             (const Name                    : PChar                  ;
                out VObj                                             )
                                                                     : LxResult;

    function ServerNameByIndex
             (      Index                   : Integer                ;
              const Name                    : PPChar                 )
                                                                     : LxResult;

    function ServerUserNameByIndex
             (      Index                   : Integer                ;
              const Name                    : PChar                  )
                                                                     : LxResult;

    function SourceCount
             (      Count                   : PInteger               )
                                                                     : LxResult;

    function SourceNameByIndex
             (      Index                   : Integer                ;
              const Name                    : PChar                  )
                                                                     : LxResult;

    function SourceUserNameByIndex
             (const Name                    : PChar                  ;
              const UserName                : PPChar                 )
                                                                     : LxResult;

    function SetImage
             (const ImageSource             : PChar                  ;
                    Image                   ,
                    FrameBuffer             : IUnknown               ;
  		    BufferIndex             : Integer                ;
  		    X1, Y1, X2, Y2          : Double                 ;
  		    ImageProc               ,
                    ProcessedThumbnail      : IUnknown               )
                                                                     : LxResult;

    function GetImage
             (const ImageSource             : PChar                  ;
                out VObj_Image                                       ;
                out VObj_FrameBuffer                                 ;
                    BufferIndex             : PInteger               ;
  		    X1, Y1, X2, Y2          : PDouble                ;
  		out VObj_ImageProc                                   ;
  	        out VObj_ProcessedThumbnail                          )
                                                                     : LxResult;

    function GetImagePacket
             (const ImageSource             : PChar                  ;
              const Packet                  : PPLXtImageMonitorPacket)
                                                                     : LxResult;

    function RefreshViews
             (const ImageSource             : PChar                  ;
                    Immediate               : Integer                )
                                                                     : LxResult;
  end;

// Macro to mask off the event
function LXxIPEVENT_EVENT(E : Integer) : Integer;
// Macro to mask off the invalidation flags
function LXxIPEVENT_FLAGS(E : Integer) : Integer;

implementation

var
  NotifierImageProcEventHints : array[0..26] of LXtTextValueHint =
  (
    // Event
    (Value : LXiIMAGEPROC_EVENT_CHANGED_SOURCE_IMAGE_GAMMA            ;
     Text  : 'sourceImageGamma'                                       ) ,

    (Value : LXiIMAGEPROC_EVENT_CHANGED_SAVE_PROCESSED                ;
     Text  : 'saveProcessed'                                          ) ,

    (Value : LXiIMAGEPROC_EVENT_CHANGED_BLOOM_ENABLED                 ;
     Text  : 'bloomEnabled'                                           ) ,

    (Value : LXiIMAGEPROC_EVENT_CHANGED_BLOOM_THRESHOLD               ;
     Text  : 'bloomThreshold'                                         ) ,

    (Value : LXiIMAGEPROC_EVENT_CHANGED_BLOOM_RADIUS                  ;
     Text  : 'bloomRadius'                                            ) ,

    (Value : LXiIMAGEPROC_EVENT_CHANGED_RESPECT_RENDER_VIEW_GAMMA_PREF;
     Text  : 'respectRenderViewGammaPref'                             ) ,

    (Value : LXiIMAGEPROC_EVENT_CHANGED_LEVEL_OFFSET                  ;
     Text  : 'levelOffset'                                            ) ,

    (Value : LXiIMAGEPROC_EVENT_CHANGED_INPUT_BLACK_LEVEL             ;
     Text  : 'inputBlackLevel'                                        ) ,

    (Value : LXiIMAGEPROC_EVENT_CHANGED_INPUT_GRAY_LEVEL              ;
     Text  : 'inputGrayLevel'                                         ) ,

    (Value : LXiIMAGEPROC_EVENT_CHANGED_INPUT_WHITE_LEVEL             ;
     Text  : 'inputWhiteLevel'                                        ) ,

    (Value : LXiIMAGEPROC_EVENT_CHANGED_INPUT_MIN_RGB_LEVEL           ;
     Text  : 'inputMinRGBLevel'                                       ) ,

    (Value : LXiIMAGEPROC_EVENT_CHANGED_INPUT_GRAY_RGB_LEVEL          ;
     Text  : 'inputGrayRGBLevel'                                      ) ,

    (Value : LXiIMAGEPROC_EVENT_CHANGED_INPUT_MAX_RGB_LEVEL           ;
     Text  : 'inputMaxRGBLevel'                                       ) ,

    (Value : LXiIMAGEPROC_EVENT_CHANGED_TONE_MAPPING                  ;
     Text  : 'toneMapping'                                            ) ,

    (Value : LXiIMAGEPROC_EVENT_CHANGED_HUE_OFFSET                    ;
     Text  : 'hueOffset'                                              ) ,

    (Value : LXiIMAGEPROC_EVENT_CHANGED_SATURATION                    ;
     Text  : 'saturation'                                             ) ,

    (Value : LXiIMAGEPROC_EVENT_CHANGED_COLORIZATION                  ;
     Text  : 'colorization'                                           ) ,

    (Value : LXiIMAGEPROC_EVENT_CHANGED_TARGET_COLOR                  ;
     Text  : 'targetColor'                                            ) ,

    (Value : LXiIMAGEPROC_EVENT_CHANGED_OUTPUT_BLACK_LEVEL            ;
     Text  : 'outputBlackLevel'                                       ) ,

    (Value : LXiIMAGEPROC_EVENT_CHANGED_OUTPUT_WHITE_LEVEL            ;
     Text  : 'outputWhiteLevel'                                       ) ,

    (Value : LXiIMAGEPROC_EVENT_CHANGED_OUTPUT_MIN_RGB_LEVEL          ;
     Text  : 'outputMinRGBLevel'                                      ) ,

    (Value : LXiIMAGEPROC_EVENT_CHANGED_OUTPUT_MAX_RGB_LEVEL          ;
     Text  : 'outputMaxRGBLevel'                                      ) ,

    (Value : LXiIMAGEPROC_EVENT_CHANGED_OUTPUT_GAMMA                  ;
     Text  : 'outputGamma'                                            ) ,

    // Invalidation flags for the event
    (Value : LXfCMDNOTIFY_VALUE                                       ;
     Text  : '+v'                                                     ) ,

    (Value : LXfCMDNOTIFY_LABEL                                       ;
     Text  : '+l'                                                     ) ,

    (Value : LXfCMDNOTIFY_DISABLE                                     ;
     Text  : '+d'                                                     ) ,

    (Value : LXfCMDNOTIFY_DATATYPE                                    ;
     Text  : '+t'                                                     )
  );

function LXxIPEVENT_EVENT(E : Integer) : Integer; inline;
begin
  Result := (LXfIPEVENT_EVENT and E);
end;
function LXxIPEVENT_FLAGS(E : Integer) : Integer; inline;
begin
  Result := (LXfIPEVENT_FLAGS and E);
end;

end.

